package com.mgr;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qy.DaoMgr;
import com.qy.bean.DriverFinance;
import com.qy.bean.Option;
import com.qy.util.StaticData;
import com.qy.util.TimeUtil;

/**
 * 提现管理
 * @author zwl
 * 2018年2月10日
 */
public class WithDrawMgr {

    public static void create(int driverId,int amount){
	DriverFinance df = new DriverFinance();
	df.setDriverId(driverId);
	df.setCreateTime(TimeUtil.getSysteCurTime());
	df.setPrice(amount);
	df.setState(StaticData.WithDrawStatus.CREATE.getType());
	df.setOp(Option.Insert);
	DaoMgr.getDriverFinanceDao().createDriverFinance(df);
    }
    
    /**
     * 获取用户提现列表
     * @param userId
     */
    public static JSONArray getListToPage(int userId){
	List<DriverFinance> list = DaoMgr.getDriverFinanceDao().getDriverFinanceList(userId);
	JSONArray jsa = new JSONArray();
	JSONObject js = null;
	if(list!=null&&list.size()>0){
	    for (DriverFinance tmp:list) {
		js = new JSONObject();
		js.put("id", tmp.getId());
		js.put("createDate", TimeUtil.getDateFormat(tmp.getCreateTime()));
		js.put("amount", tmp.getPrice());
		js.put("status", tmp.getState());
		jsa.add(js);
	    }
	}
	return jsa;
    }
}
